﻿/*
*JS Home - XDeal
*Cuong Ha - 2011.11.23
*/

$(function () {
    var jsTimerCount = new TimerCountdown();
    jsTimerCount.GetCount(
});

function TimerCountdown() {
    //===Private Functions===

    //===Public Functions===
    return {
        GetCount: function (ddate, iid) {
            dateNow = new Date(); //grab current date
            amount = ddate.getTime() - dateNow.getTime(); //calc milliseconds between dates
            delete dateNow;

            // if time is already past
            if (amount > 0) {
                hours = 0; mins = 0; secs = 0; out = "";

                amount = Math.floor(amount / 1000); //kill the "milliseconds" so just secs

                hours = Math.floor(amount / 3600); //hours
                amount = amount % 3600;

                mins = Math.floor(amount / 60); //minutes
                amount = amount % 60;

                secs = Math.floor(amount); //seconds
                if (hours < 10)
                    hours = "0" + hours;
                if (mins < 10)
                    mins = "0" + mins;
                if (secs < 10)
                    secs = "0" + secs;
                out += "<div class='h'>" + hours + "</div>";
                out += "<div class='m'>" + mins + "</div>";
                out += "<div class='s'>" + secs + "</div>";
                out = out.substr(0, out.length - 2);
                document.getElementById(iid).innerHTML = out;

                setTimeout(function () { GetCount(ddate, iid) }, 1000);
            }
        }
    };
}